<template lang="html">
  <div>
    <div class="header-abs">
        <router-link tag="div" class="iconfont icon-fanhui header-abs-back" to="/"></router-link>
    </div>
    <div class="header-fixed"  v-show="!showAbs" :style="opacityStyle">
      <router-link to="/">
        <div class="iconfont icon-fanhui header-back" ></div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity >= 1 ? 1 : top / 140
        this.showAbs = false
        this.opacityStyle = { opacity }
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  .header-abs{
    position:absolute
    left: .2rem
    top:.2rem
    width:.8rem
    height:.8rem
    line-height:.8rem
    border-radius:.4rem
    text-align:center
    background:rgba(0,0,0,.8)
    .header-abs-back{
      font-size:.4rem
      color:#fff
    }
  }

.header-fixed{
  @import '~styles/varibles.styl';
  z-index: 2
  position: fixed;
  overflow: hidden;
  top:0
  left:0
  height: $headerHeight;
  width:100%
  line-height: $headerHeight;
  background: $bgColor;
  color: #fff;
  text-align: center;
  font-size: 0.32rem;

  .header-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 0.64rem;
    text-align: center;
    font-size: 0.4rem;
    color #fff
    }
  }

</style>
